package com.softline.documentsmall.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softline.documentsmall.dao.ZsIndexInformationMapper;
import com.softline.documentsmall.entity.ZsIndexInformation;
import com.softline.documentsmall.entity.ZsIndexInformationDetailVo;
import com.softline.documentsmall.entity.ZsIndexInformationListVo;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.ZsIndexInformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 指数资讯实现类
 * @author zhongweicheng
 * @DATE 2021-03-18
 */
@Service
@Slf4j
public class ZsIndexInformationServiceImpl implements ZsIndexInformationService {

    @Autowired
    ZsIndexInformationMapper zsIndexInformationMapper;

    /**
     * 分页查询资讯 暂不根据条件查询，仅做时间倒序排序
     * @param language
     * @return
     */
    @Override
    public ReturnVO findZsIndexInfo(String language) {
       // List<ZsIndexInformationListVo> informationList = zsIndexInformationMapper.findZsIndexInfo((curNum-1)*pageSize,pageSize);

       /* Page p = new Page();
        p.setRecords(informationList);
        p.setCurrent(curNum);
        p.setPages(pageSize);
        //总数量
        p.setTotal(zsIndexInformationMapper.getTotal());*/
        List<ZsIndexInformationListVo> indexInformationList = zsIndexInformationMapper.findZsIndexInfo(language);
        return ReturnVOUtils.success(indexInformationList);
    }

    /**
     * 根据id删除资讯记录
     * @param id
     * @return
     */
    @Override
    public ReturnVO deleteZsIndexInfoById(Integer id) {
        try {
            zsIndexInformationMapper.deleteZsIndexInfoById(id);
        }catch (Exception e){
            log.error("exception{}",e.getMessage());
            return ReturnVOUtils.businessFailCustom(201,e.getMessage());
        }
        return ReturnVOUtils.success("delete success");
    }

    /**
     * 根据id更新
     * @param zsIndexInformation
     * @return
     */

    @Override
    public ReturnVO updateZsIndexInfo(ZsIndexInformation zsIndexInformation) {
        try {
            zsIndexInformationMapper.updateZsIndexInfo(zsIndexInformation);
        }catch (Exception e){
            log.error("exception{}",e.getMessage());
            return ReturnVOUtils.businessFailCustom(201,e.getMessage());
        }
        return ReturnVOUtils.success("update success");
    }

    /**
     * 新增资讯记录
     * @param zsIndexInformation
     * @return
     */
    @Override
    public ReturnVO insertZsIndexInfo(ZsIndexInformation zsIndexInformation) {
        try {
            zsIndexInformationMapper.insertZsIndexInfo(zsIndexInformation);
        }catch (Exception e){
            log.error("exception{}",e.getMessage());
            return ReturnVOUtils.businessFailCustom(201,e.getMessage());
        }
        return ReturnVOUtils.success("insert success");
    }

    //取最新发布的四个资讯
    @Override
    public ReturnVO getMoreDetail(String languageType) {
        return ReturnVOUtils.success(zsIndexInformationMapper.getMoreDetail(languageType));
    }

    @Override
    public ReturnVO getById(Integer id,String languageType) {
        //获取详情数据
        return ReturnVOUtils.success(zsIndexInformationMapper.getById(id,languageType));
    }
}
